﻿using Abp.Domain.Repositories;
using Abp.ObjectMapping;
using System.Linq;
using Teleware.Newbe.Navigation.Web.Domain.Entities;

namespace Teleware.Newbe.Navigation.Web.AppServices.Impl
{
    internal class HrefInfoService : IHrefInfoService
    {
        private readonly IRepository<HrefInfo, string> _hrefInfosRepository;
        private readonly IObjectMapper _objectMapper;

        public HrefInfoService(
            IRepository<HrefInfo, string> hrefInfosRepository,
            IObjectMapper objectMapper)
        {
            _hrefInfosRepository = hrefInfosRepository;
            _objectMapper = objectMapper;
        }

        public HrefInfoServiceGetAllOutput GetAll()
        {
            var ents = _hrefInfosRepository
                .GetAllIncluding(x => x.HrefInfoTags.Select(a => a.InfoTag), x => x.Department)
                .ToList();
            var items = _objectMapper.Map<SimpleHrefInfo[]>(ents).ToList();
            var re = new HrefInfoServiceGetAllOutput
            {
                Items = items
            };
            return re;
        }
    }
}
